<?php


namespace app\api\controller\v36;


use app\api\controller\v2\Auth;
use app\common\cachemodel\Goods;
use app\common\cachemodel\zl3\Zl3OrderpayRecommend;

class Orders extends Auth
{
    /**
     * 获取 下单好物推荐
     */
    public function getOrderpayRecommend()
    {
        $gid = input('gid/d', 0);
        if (!$gid)
        {
            return show(config('code.success'), '请求成功');
        }

        $goodsInfo = (new Goods())->getInfoById($gid);
        $extend = json_decode($goodsInfo['extend'], true);
        if (isset($extend['recommend_status']) && (int)$extend['recommend_status'] === 1)
        {
            $OrderpayRecommendModel = new Zl3OrderpayRecommend();
            $recommendGoodsInfo = $OrderpayRecommendModel->getInfoById($gid);

            if ($recommendGoodsInfo)
            {
                $OrderpayRecommendModel->updateData($recommendGoodsInfo['id'], $gid, ['num' => $recommendGoodsInfo['num'] + 1]);

                return show(config('code.success'), '请求成功', [
                    'img' => $recommendGoodsInfo['img'],
                    'target' => $recommendGoodsInfo['target'],
                    'link' => $recommendGoodsInfo['link'],
                ]);
            }
        }
        return show(config('code.success'), '请求成功');
    }
}
